﻿<UserControl x:Class="DaxStudio.UI.Views.FindReplaceDialogView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:conv="clr-namespace:DaxStudio.UI.Converters"
             xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:trig="clr-namespace:DaxStudio.UI.Triggers"
             xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro.Platform"
             xmlns:ap="clr-namespace:DaxStudio.UI.AttachedProperties"
             mc:Ignorable="d" 
             d:DesignWidth="300" 
             d:DesignHeight="100"
             Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
             Opacity="0.80"
             >
    <UserControl.Resources>
        <ResourceDictionary>
        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <BitmapImage x:Key="CaseSensitive" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/CaseSensitive.png"/>
        <BitmapImage x:Key="RegEx" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/RegEx.png"/>
        <BitmapImage x:Key="WholeWord" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/WholeWord.png"/>
        <BitmapImage x:Key="Replace" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/icon-replace_x16.png"/>
        <BitmapImage x:Key="ReplaceAll" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/icon-replace-all_x16.png"/>
        <BitmapImage x:Key="FindNext" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/FindNext.png"/>
        <BitmapImage x:Key="FindPrev" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/FindPrev.png"/>
        <BitmapImage x:Key="Close" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/Close_x16.png"/>
        <BitmapImage x:Key="CaretUp" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/CaretUp_x16.png"/>
        <BitmapImage x:Key="CaretDown" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/CaretDown_x16.png"/>
        <BitmapImage x:Key="Wildcard" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/Wildcard.png"/>

        <Style TargetType="{x:Type ToggleButton}">
            <!--<span class="code-comment"> Set the ItemTemplate of the ListBox to a DataTemplate which
           explains how to display an object of type BitmapImage. -->
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent" />
        </Style>
        <conv:ResourceLookupConverter x:Key="SearchDirections">
            <ResourceDictionary >
                <BitmapImage x:Key="Next" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/FindNext.png"/>
                <BitmapImage x:Key="Prev" UriSource="pack://application:,,,/DaxStudio.UI;component/Images/FindReplace/FindPrev.png"/>
            </ResourceDictionary>
        </conv:ResourceLookupConverter>

        <Style x:Key="ShowReplaceImageStyle" TargetType="Button">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="Content">
                <Setter.Value>
                    <Image Source="{StaticResource CaretDown}" />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                
                <DataTrigger Binding="{Binding Path=ShowReplace}" Value="True">
                    <Setter Property="Content">
                        <Setter.Value>
                            <Image Source="{StaticResource CaretUp}" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=ShowReplace}" Value="False">
                    <Setter Property="Content">
                        <Setter.Value>
                            <Image Source="{StaticResource CaretDown}" />
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>


            <Style x:Key="SearchDirectionStyle" TargetType="Fluent:SplitButton">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="BorderBrush" Value="Transparent" />
                <Setter Property="Icon">
                    <Setter.Value>
                        <Image Source="{StaticResource FindPrev}" />
                    </Setter.Value>
                </Setter>
                <Style.Triggers>

                    <DataTrigger Binding="{Binding Path=SearchUp}" Value="True">
                        <Setter Property="Icon">
                            <Setter.Value>
                                <Image Source="{StaticResource FindPrev}" />
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=SearchUp}" Value="False">
                        <Setter Property="Icon">
                            <Setter.Value>
                                <Image Source="{StaticResource FindNext}" />
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="pack://application:,,,/DaxStudio.UI;Component/Resources/DaxStudioResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid d:Visibility="True"  Visibility="{Binding Path=IsVisible,Converter={StaticResource BoolToVisibilityConverter}}"
          >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
       
        <Button Grid.Row="0" Grid.Column="0" Margin="1,5,1,0"
                VerticalAlignment="Top" x:Name="ToggleReplace" 
                IsTabStop="False"
                Style="{StaticResource ShowReplaceImageStyle}"
                ToolTip="Toggle to switch between search and replace modes"/>

        <xctk:WatermarkTextBox Name="TextToFind" Watermark="Search term"
                               Margin="3" Grid.Row="0" Grid.Column="1"
                               cal:Message.Attach="[Key Enter] = [FindText]"
                               ap:InitialFocusExtentions.SelectWhenFocused="{Binding Path=IsVisible}">
            <!-- AutoSelectBehavior="OnFocus" -->
            <!--
            <xctk:WatermarkTextBox.InputBindings>
                <KeyBinding Key="Enter" Command="Find"/>
            </xctk:WatermarkTextBox.InputBindings>
            -->
            <!--  <i:Interaction.Triggers>
                <trig:KeyPressTrigger KeyEvent="KeyUp" TriggerValue="Enter">
                    <cal:ActionMessage MethodName="Find"/>
                </trig:KeyPressTrigger>
            </i:Interaction.Triggers> -->
        </xctk:WatermarkTextBox>
        
        <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Right">
            <!--
            <xctk:SplitButton Margin="5" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="0" 
                     ToolTip="Find Next" Name="splitFind"   >
                <Image Source="{StaticResource FindNext}" />
             
                <xctk:SplitButton.DropDownContent>
                    <ListBox x:Name="SearchOptions" SelectedItem="{Binding SearchDirection}" ItemsSource="{Binding SearchDirections}">

                    </ListBox>
                </xctk:SplitButton.DropDownContent>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <cal:ActionMessage MethodName="FindText">

                        </cal:ActionMessage>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </xctk:SplitButton>
            -->
            <Fluent:SplitButton 
                Size="Small" 
                 
                Style="{StaticResource SearchDirectionStyle}"
                ToolTip="Find Next" 
                cal:Message.Attach="[Click] = [FindText]">
                <Fluent:MenuItem x:Name="FindNext" Header="Next" Icon="{StaticResource FindNext}" cal:Message.Attach="[Click] = [FindNext]" />
                <Fluent:MenuItem x:Name="FindPrev" Header="Prev" Icon="{StaticResource FindPrev}" cal:Message.Attach="[Click] = [FindPrev]" />
            </Fluent:SplitButton>
            <Button x:Name="Close" ToolTip="Close" Margin="5" BorderThickness="0" Background="Transparent" IsCancel="True" IsTabStop="False">
                <Image Source="{StaticResource Close}" />
            </Button>
        </StackPanel>

        <xctk:WatermarkTextBox Watermark="Replacement term" 
                               Visibility="{Binding ShowReplace, Converter={StaticResource BoolToVisibilityConverter }}" 
                               Margin="3" 
                               cal:Message.Attach="[Key Enter] = [ReplaceText]"
                               Name="TextToReplace" Grid.Column="1" Grid.Row="1" MinWidth="50" /> 
        
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Column="2" Grid.Row="1">
            <Button Margin="5" HorizontalAlignment="Right" 
                         ToolTip="Replace" Name="ReplaceText" Visibility="{Binding ShowReplace, Converter={StaticResource BoolToVisibilityConverter }}">
                <Image Source="{StaticResource Replace}"/>
            </Button>
            <Button Margin="5" HorizontalAlignment="Right" 
                         ToolTip="Replace All" Name="ReplaceAllText" Visibility="{Binding ShowReplace, Converter={StaticResource BoolToVisibilityConverter }}" >
                <Image Source="{StaticResource ReplaceAll}"/>
            </Button>
        </StackPanel>

        <StackPanel Orientation="Horizontal"   Grid.Row="2" Grid.Column="1">

            <ToggleButton Margin="10 2 2 2 " 
        Name="CaseSensitive"  IsChecked="False" ToolTip="Match Case">
                <Image Source="{StaticResource CaseSensitive}"></Image>
            </ToggleButton>
            <ToggleButton Margin="4,2" 
        Name="UseWholeWord" ToolTip="Match whole word" IsChecked="false">
                <Image Source="{StaticResource WholeWord}" />
            </ToggleButton>
            <ToggleButton Margin="4,2" 
        Name="UseRegex" ToolTip="Regular Expression" >
                <Image Source="{StaticResource RegEx}" />
            </ToggleButton>
            <ToggleButton Margin="4,2" BorderBrush="Transparent"
        Name="UseWildcards" ToolTip="Wildcards" Background="Transparent" >
                <Image Source="{StaticResource Wildcard}" />
            </ToggleButton>
        </StackPanel>
        <Border Height="4" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Background="{StaticResource DaxStudioBrush}" />
    </Grid>
</UserControl>
